var app = angular.module("tableApp", [])
app.controller("tablecontroller", function($scope, $http) {
	$http({
		method : 'POST',
		url : '/test/getGoods'
	}).then(function successCallback(response) {
		
		$scope.commodity=response.data;
		
		
	}, function errorCallback(response) {
		
	});
	$scope.delet=function(cId){
		
		$http({
			method : 'POST',
			url : '/test/deletGoods',
			params : {
				"id" : cId,
			}
		}).then(function successCallback(response) {
			if("Y"==response.data.rs){
				$scope.commodity=response.data.rg;
			}else if("N"==response.data.rs){
				$scope.errorMsg = "删除失败";
				$('#myModal').modal('show')
			}
			
			
			
		}, function errorCallback(response) {
			
		});
	}
	$scope.updateStart=function(c_id,c_name){
		$scope.CommodityId=c_id;
		$scope.CommodityName=c_name;
		$scope.cName=$scope.CommodityName;
		$('#myModal1').modal('show');
		// 清空模态框
		$(function() {
			$('#myModal1').on(
					'hide.bs.modal',
					function() {
						$(':input').each(
								function() {
									var type = this.type;
									var tag = this.tagName.toLowerCase(); // normalize
									// case
									if (type == 'text'|| tag == 'textarea')
										this.value = "";
									// 跌代多选checkboxes
								});
					})
		});
	}
	$scope.updateName=function(){
		$http({
			method : 'POST',
			url : '/test/updateName',
				params : {
					"cName" :$scope.update,
					"id":$scope.CommodityId
				}
		}).then(function successCallback(response) {
			$('#myModal1').modal('hide')
			if("Y"==response.data.rs){
				$scope.commodity=response.data.rg;
			}else if("N"==response.data.rs){
				$scope.errorMsg = "修改失败";
				$('#myModal').modal('show')
			}
			
			
		}, function errorCallback(response) {
			
		});
	}
	$scope.addStart=function(){
		$('#myModal2').modal('show')
		// 清空模态框
		$(function() {
			$('#myModal2').on(
					'hide.bs.modal',
					function() {
						$(':input').each(
								function() {
									var type = this.type;
									var tag = this.tagName.toLowerCase(); // normalize
									// case
									if (type == 'text'|| tag == 'textarea')
										this.value = "";
									// 跌代多选checkboxes
								});
					})
		});
	}
	$scope.findStart=function(){
		$('#myModal3').modal('show')
		// 清空模态框
		$(function() {
			$('#myModal3').on(
					'hide.bs.modal',
					function() {
						$(':input').each(
								function() {
									var type = this.type;
									var tag = this.tagName.toLowerCase(); // normalize
									// case
									if (type == 'text'|| tag == 'textarea')
										this.value = "";
									// 跌代多选checkboxes
								});
					})
		});
	}
	$scope.findC=function(){
		
		$http({
			method : 'POST',
			url : '/test/findName1',
				params : {
					"cName" :$scope.findCname
				}
		}).then(function successCallback(response) {
			$('#myModal3').modal('hide')
			if("Y"==response.data.rs){
				$scope.commodity=response.data.rg;
			}else if("N"==response.data.rs){
				$scope.errorMsg = "查找失败";
				$('#myModal').modal('show')
			}
			
			
		}, function errorCallback(response) {
			
		});
	}
	$scope.addC=function(){
		$http({
			method : 'POST',
			url : '/test/addName1',
				params : {
					"cName" :$scope.addcName
				}
		}).then(function successCallback(response) {
			$('#myModal2').modal('hide')
			if("Y"==response.data.rs){
				$scope.commodity=response.data.rg;
			}else if("N"==response.data.rs){
				$scope.errorMsg = "添加失败";
				$('#myModal').modal('show')
			}
			
			
		}, function errorCallback(response) {
			
		});
	}
	
})